#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

class Solution
{
public:
    int countDays(int days, vector<vector<int>> &meetings)
    {
        sort(meetings.begin(), meetings.end(), [](vector<int> &a, vector<int> &b)
             { return a[0] < b[0]; });
        vector<int> meeting_range;
        int length = 0;
        for (auto meeting : meetings)
        {
            if (meeting_range.empty())
            {
                meeting_range = meeting;
            }
            else if (meeting[0] <= meeting_range[1])
            {
                meeting_range[1] = max(meeting_range[1], meeting[1]);
            }
            else
            {
                length += meeting_range[1] - meeting_range[0] + 1;
                meeting_range= meeting;
            }
        }
        length += meeting_range[1] - meeting_range[0] + 1;
        return days - length;
    }
};

int main()
{
    cout << "Code3169" << endl;
    Solution s;
    vector<vector<int>> meetings = {{5, 7}, {1, 3}, {9, 10}};
    cout << s.countDays(10, meetings) << endl;
    return 0;
}

/*
class Solution
{
public:
    int countDays(int days, vector<vector<int>> &meetings)
    {
        sort(meetings.begin(), meetings.end(), [](vector<int> &a, vector<int> &b)
             { return a[0] < b[0]; });
        vector<vector<int>> meeting_range;
        for (auto meeting : meetings)
        {
            if(meeting_range.empty())
            {
                meeting_range.push_back(meeting);
            }
            else if (meeting[0] <= meeting_range.back()[1])
            {
                meeting_range.back()[1] = max(meeting_range.back()[1], meeting[1]);
            }
            else
            {
                meeting_range.push_back(meeting);
            }
        }
        int length = 0;
        for (auto meeting : meeting_range)
        {
            length += meeting[1] - meeting[0] + 1;
        }
        return days - length;
    }
};
*/